/*
 * ER/Studio 8.0 SQL Code Generation
 * Company :      Microsoft
 * Project :      DreamTeam11111111111.dm1
 * Author :       Microsoft
 *
 * Date Created : Saturday, December 10, 2011 23:27:37
 * Target DBMS : Microsoft SQL Server 2008
 */

USE master
go
CREATE DATABASE DreamTeam
go
USE DreamTeam
go
IF OBJECT_ID('Account') IS NOT NULL
BEGIN
    DROP TABLE Account
    PRINT '<<< DROPPED TABLE Account >>>'
END
go
IF OBJECT_ID('Agreement') IS NOT NULL
BEGIN
    DROP TABLE Agreement
    PRINT '<<< DROPPED TABLE Agreement >>>'
END
go
IF OBJECT_ID('Banker') IS NOT NULL
BEGIN
    DROP TABLE Banker
    PRINT '<<< DROPPED TABLE Banker >>>'
END
go
IF OBJECT_ID('Client') IS NOT NULL
BEGIN
    DROP TABLE Client
    PRINT '<<< DROPPED TABLE Client >>>'
END
go
IF OBJECT_ID('ContentPage') IS NOT NULL
BEGIN
    DROP TABLE ContentPage
    PRINT '<<< DROPPED TABLE ContentPage >>>'
END
go
IF OBJECT_ID('Credit') IS NOT NULL
BEGIN
    DROP TABLE Credit
    PRINT '<<< DROPPED TABLE Credit >>>'
END
go
IF OBJECT_ID('Currency') IS NOT NULL
BEGIN
    DROP TABLE Currency
    PRINT '<<< DROPPED TABLE Currency >>>'
END
go
IF OBJECT_ID('Deposit') IS NOT NULL
BEGIN
    DROP TABLE Deposit
    PRINT '<<< DROPPED TABLE Deposit >>>'
END
go
IF OBJECT_ID('DepositType') IS NOT NULL
BEGIN
    DROP TABLE DepositType
    PRINT '<<< DROPPED TABLE DepositType >>>'
END
go
IF OBJECT_ID('DocumentTypes') IS NOT NULL
BEGIN
    DROP TABLE DocumentTypes
    PRINT '<<< DROPPED TABLE DocumentTypes >>>'
END
go
IF OBJECT_ID('Guarantor') IS NOT NULL
BEGIN
    DROP TABLE Guarantor
    PRINT '<<< DROPPED TABLE Guarantor >>>'
END
go
IF OBJECT_ID('OrderInfo') IS NOT NULL
BEGIN
    DROP TABLE OrderInfo
    PRINT '<<< DROPPED TABLE OrderInfo >>>'
END
go
IF OBJECT_ID('OrderStatus') IS NOT NULL
BEGIN
    DROP TABLE OrderStatus
    PRINT '<<< DROPPED TABLE OrderStatus >>>'
END
go
IF OBJECT_ID('PageTemplate') IS NOT NULL
BEGIN
    DROP TABLE PageTemplate
    PRINT '<<< DROPPED TABLE PageTemplate >>>'
END
go
IF OBJECT_ID('Payment') IS NOT NULL
BEGIN
    DROP TABLE Payment
    PRINT '<<< DROPPED TABLE Payment >>>'
END
go
IF OBJECT_ID('Payments') IS NOT NULL
BEGIN
    DROP TABLE Payments
    PRINT '<<< DROPPED TABLE Payments >>>'
END
go
IF OBJECT_ID('PaymentStatus') IS NOT NULL
BEGIN
    DROP TABLE PaymentStatus
    PRINT '<<< DROPPED TABLE PaymentStatus >>>'
END
go
IF OBJECT_ID('Profile') IS NOT NULL
BEGIN
    DROP TABLE Profile
    PRINT '<<< DROPPED TABLE Profile >>>'
END
go
IF OBJECT_ID('Role') IS NOT NULL
BEGIN
    DROP TABLE Role
    PRINT '<<< DROPPED TABLE Role >>>'
END
go
IF OBJECT_ID('Tariff') IS NOT NULL
BEGIN
    DROP TABLE Tariff
    PRINT '<<< DROPPED TABLE Tariff >>>'
END
go
IF OBJECT_ID('TariffsDocuments') IS NOT NULL
BEGIN
    DROP TABLE TariffsDocuments
    PRINT '<<< DROPPED TABLE TariffsDocuments >>>'
END
go
/* 
 * TABLE: Account 
 */

CREATE TABLE Account(
    AccountId    int              IDENTITY(1,1),
    Email        nvarchar(255)    NOT NULL,
    Salt         nvarchar(255)    NOT NULL,
    Hash         nvarchar(255)    NOT NULL,
    RoleId       int              NOT NULL
)
go



IF OBJECT_ID('Account') IS NOT NULL
    PRINT '<<< CREATED TABLE Account >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Account >>>'
go

/* 
 * TABLE: Agreement 
 */

CREATE TABLE Agreement(
    BankerId       int    NOT NULL,
    AgreementId    int    IDENTITY(1,1),
    OrderId        int    NOT NULL,
    CreditId       int    NOT NULL
)
go



IF OBJECT_ID('Agreement') IS NOT NULL
    PRINT '<<< CREATED TABLE Agreement >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Agreement >>>'
go

/* 
 * TABLE: Banker 
 */

CREATE TABLE Banker(
    BankerId     int    IDENTITY(1,1),
    AccountId    int    NOT NULL,
    ProfileId    int    NOT NULL
)
go



IF OBJECT_ID('Banker') IS NOT NULL
    PRINT '<<< CREATED TABLE Banker >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Banker >>>'
go

/* 
 * TABLE: Client 
 */

CREATE TABLE Client(
    ClientId     int    IDENTITY(1,1),
    ProfileId    int    NOT NULL,
    AccountId    int    NOT NULL
)
go



IF OBJECT_ID('Client') IS NOT NULL
    PRINT '<<< CREATED TABLE Client >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Client >>>'
go

/* 
 * TABLE: ContentPage 
 */

CREATE TABLE ContentPage(
    ContentPageId     int               IDENTITY(1,1),
    Header            nvarchar(255)     NOT NULL,
    Content           ntext             NOT NULL,
    MetaContent       nvarchar(1023)    NULL,
    MetaTitle         nvarchar(255)     NULL,
    PublishDate       datetime          NOT NULL,
    Enabled           bit               NOT NULL,
    PageTemplateId    int               NOT NULL
)
go



IF OBJECT_ID('ContentPage') IS NOT NULL
    PRINT '<<< CREATED TABLE ContentPage >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE ContentPage >>>'
go

/* 
 * TABLE: Credit 
 */

CREATE TABLE Credit(
    CreditId        int         IDENTITY(1,1),
    DeliveryDate    datetime    NOT NULL,
    DepositId       int         NOT NULL
)
go



IF OBJECT_ID('Credit') IS NOT NULL
    PRINT '<<< CREATED TABLE Credit >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Credit >>>'
go

/* 
 * TABLE: Currency 
 */

CREATE TABLE Currency(
    CurrencyId    int             IDENTITY(1,1),
    Title         nvarchar(10)    NOT NULL
)
go



IF OBJECT_ID('Currency') IS NOT NULL
    PRINT '<<< CREATED TABLE Currency >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Currency >>>'
go

/* 
 * TABLE: Deposit 
 */

CREATE TABLE Deposit(
    DepositTypeId    int               NOT NULL,
    DepositId        int               IDENTITY(1,1),
    Amount           decimal(10, 0)    NULL,
    CurrencyId       int               NOT NULL,
    AccountId        int               NOT NULL
)
go



IF OBJECT_ID('Deposit') IS NOT NULL
    PRINT '<<< CREATED TABLE Deposit >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Deposit >>>'
go

/* 
 * TABLE: DepositType 
 */

CREATE TABLE DepositType(
    DepositTypeId    int              IDENTITY(1,1),
    Title            nvarchar(255)    NULL
)
go



IF OBJECT_ID('DepositType') IS NOT NULL
    PRINT '<<< CREATED TABLE DepositType >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE DepositType >>>'
go

/* 
 * TABLE: DocumentTypes 
 */

CREATE TABLE DocumentTypes(
    DocumentTypesId    int              IDENTITY(1,1),
    Title              nvarchar(255)    NOT NULL
)
go



IF OBJECT_ID('DocumentTypes') IS NOT NULL
    PRINT '<<< CREATED TABLE DocumentTypes >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE DocumentTypes >>>'
go

/* 
 * TABLE: Guarantor 
 */

CREATE TABLE Guarantor(
    GuarantorId    int               IDENTITY(1,1),
    Gains          decimal(10, 0)    NULL,
    ProfileId      int               NOT NULL,
    OrderId        int               NOT NULL
)
go



IF OBJECT_ID('Guarantor') IS NOT NULL
    PRINT '<<< CREATED TABLE Guarantor >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Guarantor >>>'
go

/* 
 * TABLE: OrderInfo 
 */

CREATE TABLE OrderInfo(
    OrderId          int               IDENTITY(1,1),
    Amount           decimal(10, 0)    NOT NULL,
    Documents        varchar(4000)     NULL,
    Gains            decimal(10, 0)    NOT NULL,
    OrderStatusId    int               NOT NULL,
    CurrencyId       int               NOT NULL,
    TariffId         int               NOT NULL,
    ClientId         int               NOT NULL
)
go



IF OBJECT_ID('OrderInfo') IS NOT NULL
    PRINT '<<< CREATED TABLE OrderInfo >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE OrderInfo >>>'
go

/* 
 * TABLE: OrderStatus 
 */

CREATE TABLE OrderStatus(
    OrderStatusId    int              IDENTITY(1,1),
    Status           nvarchar(255)    NOT NULL
)
go



IF OBJECT_ID('OrderStatus') IS NOT NULL
    PRINT '<<< CREATED TABLE OrderStatus >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE OrderStatus >>>'
go

/* 
 * TABLE: PageTemplate 
 */

CREATE TABLE PageTemplate(
    PageTemplateId          int              IDENTITY(1,1),
    ParentPageTemplateId    int              NULL,
    Name                    nvarchar(255)    NOT NULL
)
go



IF OBJECT_ID('PageTemplate') IS NOT NULL
    PRINT '<<< CREATED TABLE PageTemplate >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE PageTemplate >>>'
go

/* 
 * TABLE: Payment 
 */

CREATE TABLE Payment(
    PaymentId          int               IDENTITY(1,1),
    Date               date              NULL,
    Amount             decimal(10, 0)    NOT NULL,
    PaymentStatusId    int               NOT NULL,
    CurrencyId         int               NOT NULL,
    DepositId          int               NOT NULL
)
go



IF OBJECT_ID('Payment') IS NOT NULL
    PRINT '<<< CREATED TABLE Payment >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Payment >>>'
go

/* 
 * TABLE: Payments 
 */

CREATE TABLE Payments(
    PaymentsId    int    IDENTITY(1,1),
    PaymentId     int    NOT NULL,
    CreditId      int    NOT NULL
)
go



IF OBJECT_ID('Payments') IS NOT NULL
    PRINT '<<< CREATED TABLE Payments >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Payments >>>'
go

/* 
 * TABLE: PaymentStatus 
 */

CREATE TABLE PaymentStatus(
    PaymentStatusId    int              IDENTITY(1,1),
    Title              nvarchar(255)    NULL
)
go



IF OBJECT_ID('PaymentStatus') IS NOT NULL
    PRINT '<<< CREATED TABLE PaymentStatus >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE PaymentStatus >>>'
go

/* 
 * TABLE: Profile 
 */

CREATE TABLE Profile(
    ProfileId                   int              IDENTITY(1,1),
    Work                        nvarchar(255)    NULL,
    Adress                      nvarchar(255)    NOT NULL,
    Phone                       nvarchar(255)    NOT NULL,
    PersonalId                  nvarchar(20)     NOT NULL,
    PassportDate                date             NOT NULL,
    MiddleName                  nvarchar(255)    NULL,
    PassportIssuingAuthority    nvarchar(255)    NOT NULL,
    FirstName                   nvarchar(255)    NOT NULL,
    LastName                    nvarchar(255)    NOT NULL
)
go



IF OBJECT_ID('Profile') IS NOT NULL
    PRINT '<<< CREATED TABLE Profile >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Profile >>>'
go

/* 
 * TABLE: Role 
 */

CREATE TABLE Role(
    RoleId    int              IDENTITY(1,1),
    Title     nvarchar(255)    NOT NULL
)
go



IF OBJECT_ID('Role') IS NOT NULL
    PRINT '<<< CREATED TABLE Role >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Role >>>'
go

/* 
 * TABLE: Tariff 
 */

CREATE TABLE Tariff(
    TariffId              int               IDENTITY(1,1),
    Fine                  float             NULL,
    Title                 nvarchar(255)     NOT NULL,
    NumberOfGuarantors    int               NULL,
    Description           nvarchar(255)     NOT NULL,
    FirstPayment          decimal(10, 0)    NULL,
    OtherPayments         decimal(10, 0)    NULL,
    Time                  date              NOT NULL,
    Min                   decimal(10, 0)    NOT NULL,
    Max                   decimal(10, 0)    NOT NULL,
    CreditPercent         int               NOT NULL,
    CurrencyId            int               NOT NULL
)
go



IF OBJECT_ID('Tariff') IS NOT NULL
    PRINT '<<< CREATED TABLE Tariff >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Tariff >>>'
go

/* 
 * TABLE: TariffsDocuments 
 */

CREATE TABLE TariffsDocuments(
    TariffsDocumentsId    int    IDENTITY(1,1),
    TariffId              int    NOT NULL,
    DocumentTypeId        int    NOT NULL
)
go



IF OBJECT_ID('TariffsDocuments') IS NOT NULL
    PRINT '<<< CREATED TABLE TariffsDocuments >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE TariffsDocuments >>>'
go

/* 
 * TABLE: Account 
 */

ALTER TABLE Account ADD 
    CONSTRAINT PK1 PRIMARY KEY NONCLUSTERED (AccountId)
go

IF OBJECT_ID('Account') IS NOT NULL
    PRINT '<<< CREATED TABLE Account >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Account >>>'
go

/* 
 * TABLE: Agreement 
 */

ALTER TABLE Agreement ADD 
    CONSTRAINT PK8 PRIMARY KEY NONCLUSTERED (AgreementId)
go

IF OBJECT_ID('Agreement') IS NOT NULL
    PRINT '<<< CREATED TABLE Agreement >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Agreement >>>'
go

/* 
 * TABLE: Banker 
 */

ALTER TABLE Banker ADD 
    CONSTRAINT PK4 PRIMARY KEY NONCLUSTERED (BankerId)
go

IF OBJECT_ID('Banker') IS NOT NULL
    PRINT '<<< CREATED TABLE Banker >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Banker >>>'
go

/* 
 * TABLE: Client 
 */

ALTER TABLE Client ADD 
    CONSTRAINT PK2 PRIMARY KEY NONCLUSTERED (ClientId)
go

IF OBJECT_ID('Client') IS NOT NULL
    PRINT '<<< CREATED TABLE Client >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Client >>>'
go

/* 
 * TABLE: ContentPage 
 */

ALTER TABLE ContentPage ADD 
    CONSTRAINT PK7 PRIMARY KEY NONCLUSTERED (ContentPageId)
go

IF OBJECT_ID('ContentPage') IS NOT NULL
    PRINT '<<< CREATED TABLE ContentPage >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE ContentPage >>>'
go

/* 
 * TABLE: Credit 
 */

ALTER TABLE Credit ADD 
    CONSTRAINT PK11 PRIMARY KEY NONCLUSTERED (CreditId)
go

IF OBJECT_ID('Credit') IS NOT NULL
    PRINT '<<< CREATED TABLE Credit >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Credit >>>'
go

/* 
 * TABLE: Currency 
 */

ALTER TABLE Currency ADD 
    CONSTRAINT PK12 PRIMARY KEY NONCLUSTERED (CurrencyId)
go

IF OBJECT_ID('Currency') IS NOT NULL
    PRINT '<<< CREATED TABLE Currency >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Currency >>>'
go

/* 
 * TABLE: Deposit 
 */

ALTER TABLE Deposit ADD 
    CONSTRAINT PK20 PRIMARY KEY NONCLUSTERED (DepositId)
go

IF OBJECT_ID('Deposit') IS NOT NULL
    PRINT '<<< CREATED TABLE Deposit >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Deposit >>>'
go

/* 
 * TABLE: DepositType 
 */

ALTER TABLE DepositType ADD 
    CONSTRAINT PK22 PRIMARY KEY NONCLUSTERED (DepositTypeId)
go

IF OBJECT_ID('DepositType') IS NOT NULL
    PRINT '<<< CREATED TABLE DepositType >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE DepositType >>>'
go

/* 
 * TABLE: DocumentTypes 
 */

ALTER TABLE DocumentTypes ADD 
    CONSTRAINT PK15 PRIMARY KEY NONCLUSTERED (DocumentTypesId)
go

IF OBJECT_ID('DocumentTypes') IS NOT NULL
    PRINT '<<< CREATED TABLE DocumentTypes >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE DocumentTypes >>>'
go

/* 
 * TABLE: Guarantor 
 */

ALTER TABLE Guarantor ADD 
    CONSTRAINT PK14 PRIMARY KEY NONCLUSTERED (GuarantorId)
go

IF OBJECT_ID('Guarantor') IS NOT NULL
    PRINT '<<< CREATED TABLE Guarantor >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Guarantor >>>'
go

/* 
 * TABLE: OrderInfo 
 */

ALTER TABLE OrderInfo ADD 
    CONSTRAINT PK9 PRIMARY KEY NONCLUSTERED (OrderId)
go

IF OBJECT_ID('OrderInfo') IS NOT NULL
    PRINT '<<< CREATED TABLE OrderInfo >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE OrderInfo >>>'
go

/* 
 * TABLE: OrderStatus 
 */

ALTER TABLE OrderStatus ADD 
    CONSTRAINT PK10 PRIMARY KEY NONCLUSTERED (OrderStatusId)
go

IF OBJECT_ID('OrderStatus') IS NOT NULL
    PRINT '<<< CREATED TABLE OrderStatus >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE OrderStatus >>>'
go

/* 
 * TABLE: PageTemplate 
 */

ALTER TABLE PageTemplate ADD 
    CONSTRAINT PK6 PRIMARY KEY NONCLUSTERED (PageTemplateId)
go

IF OBJECT_ID('PageTemplate') IS NOT NULL
    PRINT '<<< CREATED TABLE PageTemplate >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE PageTemplate >>>'
go

/* 
 * TABLE: Payment 
 */

ALTER TABLE Payment ADD 
    CONSTRAINT PK17 PRIMARY KEY NONCLUSTERED (PaymentId)
go

IF OBJECT_ID('Payment') IS NOT NULL
    PRINT '<<< CREATED TABLE Payment >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Payment >>>'
go

/* 
 * TABLE: Payments 
 */

ALTER TABLE Payments ADD 
    CONSTRAINT PK19 PRIMARY KEY NONCLUSTERED (PaymentsId)
go

IF OBJECT_ID('Payments') IS NOT NULL
    PRINT '<<< CREATED TABLE Payments >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Payments >>>'
go

/* 
 * TABLE: PaymentStatus 
 */

ALTER TABLE PaymentStatus ADD 
    CONSTRAINT PK18 PRIMARY KEY NONCLUSTERED (PaymentStatusId)
go

IF OBJECT_ID('PaymentStatus') IS NOT NULL
    PRINT '<<< CREATED TABLE PaymentStatus >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE PaymentStatus >>>'
go

/* 
 * TABLE: Profile 
 */

ALTER TABLE Profile ADD 
    CONSTRAINT PK3 PRIMARY KEY NONCLUSTERED (ProfileId)
go

IF OBJECT_ID('Profile') IS NOT NULL
    PRINT '<<< CREATED TABLE Profile >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Profile >>>'
go

/* 
 * TABLE: Role 
 */

ALTER TABLE Role ADD 
    CONSTRAINT PK5 PRIMARY KEY NONCLUSTERED (RoleId)
go

IF OBJECT_ID('Role') IS NOT NULL
    PRINT '<<< CREATED TABLE Role >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Role >>>'
go

/* 
 * TABLE: Tariff 
 */

ALTER TABLE Tariff ADD 
    CONSTRAINT PK13 PRIMARY KEY NONCLUSTERED (TariffId)
go

IF OBJECT_ID('Tariff') IS NOT NULL
    PRINT '<<< CREATED TABLE Tariff >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Tariff >>>'
go

/* 
 * TABLE: TariffsDocuments 
 */

ALTER TABLE TariffsDocuments ADD 
    CONSTRAINT PK23 PRIMARY KEY NONCLUSTERED (TariffsDocumentsId)
go

IF OBJECT_ID('TariffsDocuments') IS NOT NULL
    PRINT '<<< CREATED TABLE TariffsDocuments >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE TariffsDocuments >>>'
go

/* 
 * TABLE: Account 
 */

ALTER TABLE Account ADD CONSTRAINT RefRole10 
    FOREIGN KEY (RoleId)
    REFERENCES Role(RoleId)
go


/* 
 * TABLE: Agreement 
 */

ALTER TABLE Agreement ADD CONSTRAINT RefBanker14 
    FOREIGN KEY (BankerId)
    REFERENCES Banker(BankerId)
go

ALTER TABLE Agreement ADD CONSTRAINT RefOrderInfo17 
    FOREIGN KEY (OrderId)
    REFERENCES OrderInfo(OrderId)
go

ALTER TABLE Agreement ADD CONSTRAINT RefCredit19 
    FOREIGN KEY (CreditId)
    REFERENCES Credit(CreditId)
go


/* 
 * TABLE: Banker 
 */

ALTER TABLE Banker ADD CONSTRAINT RefAccount4 
    FOREIGN KEY (AccountId)
    REFERENCES Account(AccountId)
go

ALTER TABLE Banker ADD CONSTRAINT RefProfile5 
    FOREIGN KEY (ProfileId)
    REFERENCES Profile(ProfileId)
go


/* 
 * TABLE: Client 
 */

ALTER TABLE Client ADD CONSTRAINT RefProfile2 
    FOREIGN KEY (ProfileId)
    REFERENCES Profile(ProfileId)
go

ALTER TABLE Client ADD CONSTRAINT RefAccount3 
    FOREIGN KEY (AccountId)
    REFERENCES Account(AccountId)
go


/* 
 * TABLE: ContentPage 
 */

ALTER TABLE ContentPage ADD CONSTRAINT RefPageTemplate8 
    FOREIGN KEY (PageTemplateId)
    REFERENCES PageTemplate(PageTemplateId)
go


/* 
 * TABLE: Credit 
 */

ALTER TABLE Credit ADD CONSTRAINT RefDeposit47 
    FOREIGN KEY (DepositId)
    REFERENCES Deposit(DepositId)
go


/* 
 * TABLE: Deposit 
 */

ALTER TABLE Deposit ADD CONSTRAINT RefDepositType35 
    FOREIGN KEY (DepositTypeId)
    REFERENCES DepositType(DepositTypeId)
go

ALTER TABLE Deposit ADD CONSTRAINT RefCurrency37 
    FOREIGN KEY (CurrencyId)
    REFERENCES Currency(CurrencyId)
go

ALTER TABLE Deposit ADD CONSTRAINT RefAccount45 
    FOREIGN KEY (AccountId)
    REFERENCES Account(AccountId)
go


/* 
 * TABLE: Guarantor 
 */

ALTER TABLE Guarantor ADD CONSTRAINT RefProfile24 
    FOREIGN KEY (ProfileId)
    REFERENCES Profile(ProfileId)
go

ALTER TABLE Guarantor ADD CONSTRAINT RefOrderInfo48 
    FOREIGN KEY (OrderId)
    REFERENCES OrderInfo(OrderId)
go


/* 
 * TABLE: OrderInfo 
 */

ALTER TABLE OrderInfo ADD CONSTRAINT RefOrderStatus12 
    FOREIGN KEY (OrderStatusId)
    REFERENCES OrderStatus(OrderStatusId)
go

ALTER TABLE OrderInfo ADD CONSTRAINT RefCurrency21 
    FOREIGN KEY (CurrencyId)
    REFERENCES Currency(CurrencyId)
go

ALTER TABLE OrderInfo ADD CONSTRAINT RefTariff22 
    FOREIGN KEY (TariffId)
    REFERENCES Tariff(TariffId)
go

ALTER TABLE OrderInfo ADD CONSTRAINT RefClient46 
    FOREIGN KEY (ClientId)
    REFERENCES Client(ClientId)
go


/* 
 * TABLE: PageTemplate 
 */

ALTER TABLE PageTemplate ADD CONSTRAINT RefPageTemplate7 
    FOREIGN KEY (ParentPageTemplateId)
    REFERENCES PageTemplate(PageTemplateId)
go


/* 
 * TABLE: Payment 
 */

ALTER TABLE Payment ADD CONSTRAINT RefPaymentStatus29 
    FOREIGN KEY (PaymentStatusId)
    REFERENCES PaymentStatus(PaymentStatusId)
go

ALTER TABLE Payment ADD CONSTRAINT RefCurrency36 
    FOREIGN KEY (CurrencyId)
    REFERENCES Currency(CurrencyId)
go

ALTER TABLE Payment ADD CONSTRAINT RefDeposit38 
    FOREIGN KEY (DepositId)
    REFERENCES Deposit(DepositId)
go


/* 
 * TABLE: Payments 
 */

ALTER TABLE Payments ADD CONSTRAINT RefPayment31 
    FOREIGN KEY (PaymentId)
    REFERENCES Payment(PaymentId)
go

ALTER TABLE Payments ADD CONSTRAINT RefCredit32 
    FOREIGN KEY (CreditId)
    REFERENCES Credit(CreditId)
go


/* 
 * TABLE: Tariff 
 */

ALTER TABLE Tariff ADD CONSTRAINT RefCurrency23 
    FOREIGN KEY (CurrencyId)
    REFERENCES Currency(CurrencyId)
go


